<template>
  <div id="modify-certi">
    <p class="title-pad20">证书基本信息</p>
    <el-form :model="gwInfoForm" ref="ruleForm" label-width="130px" class="demo-ruleForm">
      <el-row>
        <el-col :push=2 :span=10>
          <el-form-item label="网关ID:" prop="gwEnvId">
            <el-input v-model="gwInfoForm.gwEnvId" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :push=2 :span=10>
          <el-form-item label="证书ID:" prop="keyId">
            <el-select v-model="gwInfoForm.keyId" placeholder="请选择">
              <el-option
                v-for="item in keyArr"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col>
          <el-button type="primary" @click="submit">确认</el-button>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import api from '../../../../../api/url'
import ajax from '../../../../../api/ajax/ajax'
export default {
  data () {
    return {
      gwInfoForm: {
        gwEnvId: '',
        keyId: ''
      },
      keyArr: []
    }
  },
  methods: {
    submit () {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          ajax.post(api.UPDATA_PRI, this.gwInfoForm).then((res) => {
            if (res === 'success') {
              this.$message({
                type: 'success',
                message: '修改成功'
              })
            }
            this.$emit('refresh')
          }).catch(err => {
            console.info(err)
          })
        }
      })
    }
  },
  mounted () {
    this.$on('modifyCerti', ({id, selectData, keyIdResDat}) => {
      this.gwInfoForm.gwEnvId = id
      this.gwInfoForm.keyId = selectData.gwKeyId
      this.keyArr = keyIdResDat.list.map(item => {
        let keyIdArr = {
          value: item.KeyId,
          label: item.keycode
        }
        return keyIdArr
      })
    })
  }
}
</script>
<style lang="stylus" rel="stylesheet/stylus">
  #modify-certi
    background #ffffff
    padding-bottom 30px
    .title-pad20
      height: 40px
      line-height 40px
      padding-left 20px
    .el-form-item__label
      width 120px
    .el-select
    .el-input
      width 100%
    .el-col-10
      // margin-top 10px
    .el-col-24
      text-align center
      margin-top 35px
</style>
